#ifndef __TUYA_SERVICE_H__
#define __TUYA_SERVICE_H__

#include "mlist.h"
#include "platform.h"

#include "tal_api.h"
#include "tuya_iot.h"

#define URL_MAX_LEN	255

struct url {
	char shorturl[URL_MAX_LEN + 1];
	uint32_t valid;
};

#define 	RDONLY		0
#define 	RDWR		1

struct mty_dpattr_t {
	uint8_t type;
	uint8_t rdwr;
	uint8_t dp_id;
	uint32_t db_addr;
	void (*upload_hook)(void *dpattr, dp_obj_t *dp);
	void (*download_hook)(void *dpattr, dp_obj_t *dp);
};

struct mty_upload_t {
	struct mlist_head list;
	uint32_t addr;
	int32_t value;
	int32_t min;
	int32_t max;
	uint8_t type;
	uint8_t dp_id;
};

struct mtuya_t {
	MDB_MUTEX lock;

	struct mlist_head upload_list;		
	int8_t tuya_online;
	char devid[32];

	uint32_t mdps_num;
	struct mty_dpattr_t *mdps;

	uint32_t cache_num;
	dp_obj_t *dpup_cache;
	
} ;

int tuya_upload_handler(tuya_iot_client_t *client, void *userdata);
void tuya_upload_all_dpobjs(void);
int tuya_download_dpobjs(dp_obj_recv_t *dpobj);
void tuya_service_init(struct mty_dpattr_t *dpattr, uint32_t num);


#endif
